package com.guoq.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.guoq.constant.Configration;
import com.guoq.pojo.Cart;
import com.guoq.pojo.CartItem;
import com.guoq.pojo.EUDataGridResult;
import com.guoq.pojo.Result;
import com.guoq.service.ICartItemService;
import com.guoq.utils.Strkit;

/**
 * 
 * <P>类名称:CartItemController
 * <P>类描述:  购物车商品项Controller
 * <P>创建人:郭强  
 * <P>修改人:XXX 
 * <P>修改时间:2017年7月19日 上午11:45:35
 * <P>修改备注: 
 * @version 1.0.0
 * Copyright(c)2017西部在线-版权所有
 */
@Controller
@RequestMapping("/cartitem")
public class CartItemController {
	@Resource
	private ICartItemService cartItemService;
	
	@RequestMapping("/")
	public ModelAndView toList(CartItem record, Integer page, Integer rows) {
		
		if(Strkit.notBlank("" + page)){
			page = 1;
		}
		
		if(Strkit.notBlank("" + rows)){
			rows = Configration.PAGESIZE;
		}
		ModelAndView modelAndView = new ModelAndView();
		EUDataGridResult result = cartItemService.getPageList(record, page, rows);
		modelAndView.addObject("result", result);
		modelAndView.setViewName("/cart/list");
		return modelAndView;
	}
	
	@RequestMapping("/toadd")
	public String toadd(HttpServletRequest request,Model model){
		return "/cart/add";
	}
	
	@RequestMapping("/toedit")
	public String toedit(HttpServletRequest request,Model model){
		return "/cart/edit";
	}
	
	/**
	 * 
	 *<P>开发者:郭强
	 *<P>方法名: getShopById
	 *<P>描述: 根据id获取店铺信息
	 *@param request
	 *@param model
	 *@return   
	 *@exception   
	 *@since  1.0.0
	 */
	@RequestMapping("/getById")
	@ResponseBody
	public CartItem getById(HttpServletRequest request,Model model){
		
		int id = Integer.parseInt(request.getParameter("id"));
		CartItem record = this.cartItemService.getById(id);
		return record;
	}
	
	/**
	 * 
	 *<P>开发者:郭强
	 *<P>方法名: list
	 *<P>描述: 获取店铺列表
	 *@param request
	 *@param model
	 *@return   
	 *@exception   
	 *@since  1.0.0
	 */
	@RequestMapping("/list")
	@ResponseBody
	public List<CartItem> list(HttpServletRequest request,Model model){
		
		List<CartItem> list = this.cartItemService.getList();
		return list;
	}
	
	/**
	 * 
	 *<P>开发者:郭强
	 *<P>方法名: pageList
	 *<P>描述: 获取店铺列表（分页）
	 *@param page
	 *@param rows
	 *@return   
	 *@exception   
	 *@since  1.0.0
	 */
	@RequestMapping(value="/pagelist")
	@ResponseBody
	public EUDataGridResult pageList(CartItem record, Integer page, Integer rows) {
		
		if(Strkit.notBlank("" + page)){
			page = 1;
		}
		
		if(Strkit.notBlank("" + rows)){
			rows = Configration.PAGESIZE;
		}
		
		EUDataGridResult result = cartItemService.getPageList(record, page, rows);
		return result;
	}
	
	/**
	 * 
	 *<P>开发者:郭强
	 *<P>方法名: add
	 *<P>描述: 新增
	 *@param shop
	 *@return   
	 * @throws Exception 
	 *@exception   
	 *@since  1.0.0
	 */
	@RequestMapping(value="/save", method=RequestMethod.POST)
	@ResponseBody
	public Result add(CartItem record) throws Exception{
		
		Result result = this.cartItemService.create(record);
		return result;
	} 
	
	/**
	 * 
	 *<P>开发者:郭强
	 *<P>方法名: update
	 *<P>描述: 编辑
	 *@param cart
	 *@return
	 *@throws Exception   
	 *@exception   
	 *@since  1.0.0
	 */
	@RequestMapping(value="/update", method=RequestMethod.POST)
	@ResponseBody
	public Result update(CartItem record) throws Exception{
		
		Result result = this.cartItemService.update(record);
		return result;
	} 
	
	/**
	 * 
	 *<P>开发者:郭强
	 *<P>方法名: delete
	 *<P>描述:	删除 
	 *@param id
	 *@return
	 *@throws Exception   
	 *@exception   
	 *@since  1.0.0
	 */
	@RequestMapping(value="/delete")
	@ResponseBody
	public Result delete(Cart record) throws Exception{
//		HttpServletRequest request, 
//		User request.getSession().getAttribute("");
//		Result result = this.cartService.delete(record);
//		return result;
		return null;
	}
	
}
